function getxhr(){
	var xhr = false;
	if(window . XMLHttpRequest){
		xhr = new XMLHttpRequest();
	}else{
		xhr = window . ActiveXObject('Microsoft . XMLHttp');
	}
	return xhr;
}

function goodsbox(cat_id, property){
	
	var url = 'index.php?act=goodsbox&property=' + property + '&cat_id=' + cat_id;
	var xhr = getxhr();
	xhr.open('GET', url, true);
	xhr.onreadystatechange = function (){
		
		if(xhr.readyState == 4){
			console.log('fafaf');
			var goodsbox = eval('(' + this.responseText + ')');
			var id = 'show_' + property + '_area';
			var div = document.getElementById(id);
			var html = '';
			for(var i=0,len=goodsbox.length; i<len; i++){
				html += '<div class="goodsbox" >';
				html += '<div class="imgbox"><a href="goods.php?goods_id=' + goodsbox[i]['goods_id'] + '"><img src="../' + goodsbox[i]['goods_thumb'] + '" alt="" /></a></div>';
				html += '<a href="goods.php?id=32" title="">' + goodsbox[i]['goods_name'] + '</a><br />';
				html += '<font class="goodspice market">￥' + goodsbox[i]['market_price'] + '</font>';
				html += '<b class="f1">￥' + goodsbox[i]['shop_price'] + '</b><br />';
				html += '</div>';
			}
			div.innerHTML = html;
		}
		
	}
	
	xhr.send(null);
	
}

/*
var historyProduct = getCookie("historyProduct");
var historyProductIds = historyProduct != null ? historyProduct.split(",") : new Array();
for (var i = 0; i < historyProductIds.length; i ++) {
	if (historyProductIds[i] == "${product.id}") {
		historyProductIds.splice(i, 1);
		break;
	}
}
historyProductIds.unshift("${product.id}");
if (historyProductIds.length > 6) {
	historyProductIds.pop();
}
addCookie("historyProduct", historyProductIds.join(","), {path: "${base}/"});
$.ajax({
	url: "${base}/product/history.jhtml",
	type: "GET",
	data: {ids: historyProductIds},
	dataType: "json",
	traditional: true,
	cache: false,
	success: function(data) {
		$.each(data, function (index, product) {
			var thumbnail = product.thumbnail != null ? product.thumbnail : "${setting.defaultThumbnailProductImage}";
			$historyProduct.append('<li><img src="' + thumbnail + '" \/><a href="${base}' + product.path + '">' + product.name + '<\/a><span>' + currency(product.price, true) + '<\/span><\/li>');
		});
	}
});

// 清空浏览记录
$clearHistoryProduct.click(function() {
	$historyProduct.empty();
	$(this).text("${message("shop.product.noHistoryProduct")}");
	removeCookie("historyProduct", {path: "${base}/"});
});

//添加Cookie
function addCookie(name, value, options) {
if (arguments.length > 1 && name != null) {
	if (options == null) {
		options = {};
	}
	if (value == null) {
		options.expires = -1;
	}
	if (typeof options.expires == "number") {
		var time = options.expires;
		var expires = options.expires = new Date();
		expires.setTime(expires.getTime() + time * 1000);
	}
	document.cookie = encodeURIComponent(String(name)) + "=" + encodeURIComponent(String(value)) + (options.expires ? "; expires=" + options.expires.toUTCString() : "") + (options.path ? "; path=" + options.path : "") + (options.domain ? "; domain=" + options.domain : ""), (options.secure ? "; secure" : "");
}
}

//获取Cookie
function getCookie(name) {
if (name != null) {
	var value = new RegExp("(?:^|; )" + encodeURIComponent(String(name)) + "=([^;]*)").exec(document.cookie);
	return value ? decodeURIComponent(value[1]) : null;
}
}

//移除Cookie
function removeCookie(name, options) {
addCookie(name, null, options);
}
*/


/*function goodsbox(obj, cat_id){
	$.ajax({
		url: "index.php?act=goodsbox&cat_id=" + cat_id;
		type: "GET",
		data: "json",
		cache: false,
		success: function(data) {
			//var json = JSON.parse(data);
			console.log($(obj).html());
			
		}
	});
}*/